package com.learn.eduorder.listener;

import com.learn.eduorder.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class PayCallbackListener {

    public static final String KEY = "queue.pay.callback";
    public static final String EXCHANGE = "pay.callback.exchange";

    @Autowired
    private IOrderService orderService;

    /**
     * 监听课程删除操作
     */
    @RabbitListener(bindings = {
            @QueueBinding(value = @Queue(value = KEY, durable = "true"),
                    exchange = @Exchange(value = EXCHANGE,
                            type = ExchangeTypes.TOPIC,
                            ignoreDeclarationExceptions = "true")
                    , key = KEY)})
    public void receivePayCallbackMessage(String tradeNo) {
        log.info("微信支付订单{}",tradeNo);
        orderService.finishPay(tradeNo);
    }
}
